<template>
    <div class="mainbody">
      <el-row>
        <!-- 获取所有的订单 -->
            <el-col :span="7" v-for="(Order,index) in GetAllGoodsOrder" :key="index" style="position: relative;margin:20px 20px">
                <el-card style=" padding: 14px;">
                  <el-row>
                    <img :src="Order.goodsImage">
                    <el-col :span="5">
                        {{ Order.goodsName }}
                    </el-col>
                    <el-col :span="10">
                        价格：¥{{ Order.goodsBuyPrice }}
                        <span disabled>x{{ Order.goodsBuyCount }}</span>
                    </el-col>
                    <el-col :span="9">
                        <strong>实付款：</strong>¥{{ Order.goodsBuyAllPrice }}
                    </el-col>
                    <el-button-group>
                      <el-button type="primary" round @click="UpdateGoodsOrderById(Order)">更新订单</el-button>
                      <el-button type="primary" round @click="DeleteGoodsBuyRecordsByUserNameAndBuyRecordId(Order)">订单回收<i class="el-icon-delete"></i></el-button>
                    </el-button-group>
                  </el-row>
                </el-card>
            </el-col>
        </el-row>
    </div>
</template>
  
  <script>
  import {getAllGoodsOrder,userInfo,updateGoodsOrderById,deleteGoodsBuyRecordsByUserNameAndBuyRecordId} from "../../../ajax/get"
//   import {addGoodsOrder} from "../ajax/post"
//   import defaultValue from "../utils/defalutValue"
  export default {
      name: "getGoodsOrder",
      data () {
          return {
            nickName: "", // 昵称
            userName:"",//用户名
            GetAllGoodsOrder:[],//获取所有订单列表
          };
      },
      methods: {
              // 查找用户信息
      findUserInfo(userName) {
        userInfo(userName).then(res => {
          console.log("用户信息:",res);
          this.nickName = res.data.data.nickName;
          this.userName = res.data.data.userName;
        })
        // 获取所有订单
        getAllGoodsOrder(sessionStorage.getItem("userName")).then(com => {
            this.GetAllGoodsOrder = com.data.data;
            console.log(this.GetAllGoodsOrder,"所有订单信息111");
          })
        },
        // 更新订单状态
        UpdateGoodsOrderById(Order){
            let goodsStatus=Order.goodsStatus+1;
            updateGoodsOrderById(goodsStatus,Order.id).then(res =>{
            console.log("更新订单状态:",res);
            })
        },
        // 删除订单
        DeleteGoodsBuyRecordsByUserNameAndBuyRecordId(Order){
            deleteGoodsBuyRecordsByUserNameAndBuyRecordId(Order.id,sessionStorage.getItem("userName")).then( res =>{
                console.log("删除订单",res);
                this.findUserInfo(sessionStorage.getItem("userName"));
            })
        },
      },
      created() {
      this.findUserInfo(sessionStorage.getItem("userName"));
          
      }
  }
  </script>
  
  <style scoped>
  </style>